<template>
  <div class="mod-config">
    <basic-container>
      <!--新增跳转-->
      <div :class="zhibiaoForm.enter == 0 ? '' : 'boxsty'">
        <div
          v-if="
            zhibiaoForm.enter == 0 ||
            zhibiaoForm.enter == 2 ||
            zhibiaoForm.enter == 3
          "
        >
          <div :height="searchheight">
            <span
              v-if="zhibiaoForm.enter != 0"
              style="float: right; margin-top: -30px; cursor: pointer"
              @click="searchchangeadvanced"
              >{{ searchadvanced ? "收起" : "展开" }}
              <i
                :class="
                  searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
                "
              />
            </span>
            <div v-if="searchadvanced">
              <contractDetailHeader
                :contractDetailHeaderData="zhibiaoForm.rows"
              ></contractDetailHeader>
            </div>
            <div>
              <div>
                <div class="mt20">
                  <div
                    class="flex"
                    style="margin-bottom: 20px; justify-content: space-between"
                  >
                    <div>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="业绩合同指标库"
                        placement="top-start"
                        v-if="
                          (zhibiaoForm.enter == 0 && !zhibiaoForm.isHideBtn) ||
                          zhibiaoForm.contractAuditStatus == 3
                        "
                      >
                        <el-button
                          icon="el-icon-plus"
                          type="primary"
                          v-if="
                            (zhibiaoForm.enter == 0 &&
                              !zhibiaoForm.isHideBtn) ||
                            zhibiaoForm.contractAuditStatus == 3
                          "
                          @click="showZhibiaoTable"
                          circle
                        ></el-button>
                      </el-tooltip>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="保存"
                        placement="top-start"
                        v-if="zhibiaoForm.enter == 0 && !zhibiaoForm.isHideBtn"
                      >
                        <el-button
                          plain
                          icon="el-icon-check"
                          v-if="
                            zhibiaoForm.enter != 2 && zhibiaoForm.enter != 0
                          "
                          @click="saveZBData"
                          circle
                        ></el-button>
                      </el-tooltip>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="返回"
                        placement="top-start"
                      >
                        <el-button
                          plain
                          icon="el-icon-back"
                          v-if="
                            zhibiaoForm.enter != 2 && zhibiaoForm.enter != 0
                          "
                          @click="close('关闭')"
                          circle
                        ></el-button>
                      </el-tooltip>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="导出"
                        placement="top-start"
                      >
                        <el-button
                          plain
                          type="info"
                          icon="el-icon-download"
                          v-if="zhibiaoForm.enter == 0 && hetongId"
                          @click="exportExcel()"
                          circle
                        ></el-button>
                      </el-tooltip>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="批量删除"
                        placement="top-start"
                        v-if="zhibiaoForm.enter == 0 && !zhibiaoForm.isHideBtn"
                      >
                        <el-button
                          plain
                          type="danger"
                          icon="el-icon-delete"
                          v-if="zhibiaoForm.enter == 0"
                          @click="deleteBatch()"
                          circle
                        ></el-button>
                      </el-tooltip>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="保存顺序"
                        placement="top-start"
                      >
                        <el-button
                          type="primary"
                          plain
                          icon="el-icon-folder-opened"
                          @click="saveOrderBtn()"
                          circle
                        ></el-button>
                      </el-tooltip>
                    </div>
                    <div style="display: flex">
                      <el-button
                        plain
                        v-if="zhibiaoForm.enter == 1"
                        type="primary"
                        @click="close('关闭')"
                        >关闭窗口</el-button
                      >
                      <div
                        v-if="zhibiaoForm.enter == 0 && !zhibiaoForm.isHideBtn"
                      >
                        <el-button
                          type="primary"
                          plain
                          v-if="zhibiaoForm.enter == 0"
                          @click="copyZhibiao('fy')"
                          >复用指标</el-button
                        >

                        <el-button
                          type="primary"
                          plain
                          v-if="
                            zhibiaoForm.enter == 0 &&
                            zhibiaoForm.titleName != '新增'
                          "
                          @click="copyZhibiao('ts')"
                          >推送到其他合同</el-button
                        >
                      </div>

                      <el-button
                        type="danger"
                        plain
                        v-if="
                          zhibiaoForm.taskDefKey.indexOf('usertask5') != -1 ||
                          zhibiaoForm.taskDefKey.indexOf('usertask8') != -1
                        "
                        @click="rejectedBtn"
                        >驳 回</el-button
                      >
                    </div>
                    <div v-if="zhibiaoForm.enter == 2">
                      <el-button plain type="primary" @click="okAll"
                        >同意</el-button
                      >
                      <el-button
                        plain
                        type="primary"
                        v-if="this.htqdorwbsh == 'wbsh'"
                        @click="backAll"
                        >驳回</el-button
                      >
                      <el-button plain type="primary" @click="close('关闭')"
                        >返回</el-button
                      >
                      <el-button plain type="primary" @click="exportExcel"
                        >导出</el-button
                      >
                    </div>

                    <!--                        <el-button type="primary" v-if="zhibiaoForm.enter==2||zhibiaoForm.enter==3">导出</el-button>-->
                    <!--                        <el-button type="primary" v-if="zhibiaoForm.enter==3">打印</el-button>-->
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--指标编辑-->
        <div>
          <div :height="searchheight" v-if="zhibiaoForm.enter == 1">
            <span
              style="float: right; margin-top: -30px; cursor: pointer"
              @click="searchchangeadvanced"
              >{{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
              <i
                :class="
                  searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'
                "
              />
            </span>
            <div v-if="searchadvanced">
              <contractDetailHeader
                :contractDetailHeaderData="zhibiaoForm.rows"
              ></contractDetailHeader>
            </div>
            <div v-show="searchadvanced">
              <div class="flex">
                <div>
                  <el-form :model="form" :inline="true" class="form-inline">
                    <el-form-item label="指标名称">
                      <el-input
                        v-model="form.zhibiaoName"
                        placeholder="指标名称"
                        style="width: 150px"
                        :clearable="true"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="指标类别">
                      <el-input
                        v-model="form.zhibiaoType"
                        placeholder="指标类别"
                        style="width: 150px"
                        :clearable="true"
                      ></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        icon="el-icon-search"
                        type="primary"
                        class="marginLeft"
                        @click="getDataList(1)"
                        >检索</el-button
                      >
                    </el-form-item>
                  </el-form>
                </div>
              </div>
            </div>
          </div>
          <div
            style="
              padding: 10px 0;
              display: flex;
              justify-content: space-between;
            "
            v-if="zhibiaoForm.enter == 1"
          >
            <div style="float: left">
              <el-tooltip
                class="item"
                effect="dark"
                content="业绩合同指标库"
                placement="top-start"
                v-if="this.editFlag == 1 && zhibiaoForm.status != 1"
              >
                <el-button
                  plain
                  icon="el-icon-plus"
                  type="primary"
                  v-if="this.editFlag == 1 && zhibiaoForm.status != 1"
                  @click="showZhibiaoTable"
                  circle
                ></el-button>
              </el-tooltip>
              <el-tooltip
                class="item"
                effect="dark"
                content="保存"
                placement="top-start"
              >
                <el-button
                  plain
                  icon="el-icon-check"
                  @click="saveZBData"
                  circle
                ></el-button>
              </el-tooltip>
              <el-tooltip
                class="item"
                effect="dark"
                content="批量删除"
                placement="top-start"
                v-if="this.editFlag == 1"
              >
                <el-button
                  plain
                  type="danger"
                  icon="el-icon-delete"
                  @click="deleteBatch()"
                  circle
                ></el-button>
              </el-tooltip>
            </div>
            <div>
              <div style="display: flex">
                <el-button
                  type="primary"
                  plain
                  @click="copyZhibiao('fy')"
                  v-if="zhibiaoForm.status != 1"
                  >复用指标</el-button
                >
                <el-button
                  plain
                  type="primary"
                  @click="copyZhibiao('ts')"
                  v-if="zhibiaoForm.status != 1"
                  >推送到其他合同</el-button
                >
                <el-button
                  plain
                  type="primary"
                  @click="exportExcel"
                  v-if="zhibiaoForm.status != 1"
                  >导出</el-button
                >
                <el-upload
                  v-if="zhibiaoForm.enter == 1"
                  class="upload-demo"
                  action="/admin/sys-file/upload"
                  accept=".xls,.xlsx"
                  :headers="headers"
                  :before-upload="beforeFileUpload"
                  :on-change="handleChange"
                  :on-success="handleUploadSuccess"
                  :show-file-list="false"
                  :file-list="fileList"
                >
                  <el-button size="small" type="primary" style="margin: 0 10px"
                    >导入</el-button
                  >
                  <!--:show-file-list="false" -->
                  <!--<div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件</div>-->
                </el-upload>
                <el-button
                  v-if="zhibiaoForm.enter == 1"
                  plain
                  type="primary"
                  @click="close('关闭')"
                  >关闭窗口</el-button
                >
              </div>
            </div>
          </div>
          <el-table
            :data="dataList"
            border
            style="width: 100%"
            min-height="60vh"
            v-if="zhibiaoForm.enter == 0 || zhibiaoForm.enter == 1"
            v-loading="dataListLoading"
            class="avue-cruds"
            :row-key="getRowKeys"
            ref="table"
          >
            <el-table-column
              type="selection"
              width="55"
              header-align="center"
              :disabled="zhibiaoForm.status == 1"
              align="center"
              :selectable="selectable"
            ></el-table-column>
            <el-table-column
              prop="zhibiaoType"
              label="指标类别"
              min-width="90"
              header-align="center"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="zhibiaoName"
              label="指标名称"
              min-width="120"
              show-overflow-tooltip
              header-align="center"
              align="left"
            >
            </el-table-column>

            <el-table-column
              prop="weight"
              label="权重(%)"
              min-width="110"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <span v-if="editFlag == 0 || zhibiaoForm.status == 1">
                  {{ scope.row.weight }}
                </span>
                <el-input
                  v-else
                  type="number"
                  min="0.1"
                  max="100"
                  oninput="if(value>100)value=100;
                                      if(value<0)value=0;"
                  v-model="scope.row.weight"
                  placeholder="请输入内容"
                  @change="saveProperty(scope.row, scope.$index)"
                />
                <!--                       </span>
               <span v-else>{{ scope.row.weight }}</span>-->
              </template>
            </el-table-column>
            <el-table-column
              prop="formulaId"
              label="计算公式"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-if="editFlag == 0 && zhibiaoForm.contractAuditStatus == 10"
                  v-model="scope.row.formulaId"
                  placeholder="请选择"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in formulaOptions"
                    :key="item.id"
                    :label="item.gsMc"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
                <div v-else-if="editFlag == 0 || zhibiaoForm.status == 1">
                  <span v-for="item in formulaOptions">
                    <span v-if="item.id == scope.row.formulaId">
                      {{ item.gsMc }}
                    </span>
                  </span>
                </div>

                <el-select
                  v-else
                  v-model="scope.row.formulaId"
                  placeholder="请选择"
                  :clearable="true"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in formulaOptions"
                    :key="item.id"
                    :label="item.gsMc"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="targetValue"
              label="目标值"
              min-width="250"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <div
                  style="white-space: pre-wrap"
                  v-if="editFlag == 0 || zhibiaoForm.status == 1"
                  v-html="scope.row.targetValue"
                ></div>
                <el-input
                  type="textarea"
                  v-else
                  :rows="3"
                  style="white-space: pre-wrap"
                  v-model="scope.row.targetValue"
                  placeholder="请输入内容"
                  @change="saveProperty(scope.row, scope.$index)"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="unit"
              label="单位"
              min-width="80"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <span v-if="editFlag == 0 || zhibiaoForm.status == 1">
                  {{ scope.row.unit }}
                </span>
                <!--                       <span v-if="scope.row.edit">-->
                <el-input
                  v-else
                  v-model="scope.row.unit"
                  placeholder="请输入内容"
                  @change="saveProperty(scope.row, scope.$index)"
                />
                <!--                       </span>
               <span v-else>{{ scope.row.unit }}</span>-->
              </template>
            </el-table-column>
            <el-table-column
              prop="shangnianvalue"
              label="上年度完成值"
              min-width="120"
              header-align="center"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="increaseDecrease"
              label="增减幅度"
              min-width="90"
              header-align="center"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="targetValueType"
              label="完成值获取方式"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-if="editFlag == 0 && zhibiaoForm.contractAuditStatus == 10"
                  v-model="scope.row.targetValueType"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
                <div v-else-if="editFlag == 0 || zhibiaoForm.status == 1">
                  <span v-for="item in typeList">
                    <span v-if="item.value == scope.row.targetValueType">
                      {{ item.name }}
                    </span>
                  </span>
                </div>
                <el-select
                  v-else
                  v-model="scope.row.targetValueType"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="dataProviderId"
              label="数据提供部门/人"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <!--                合同创建-->
                <div v-if="zhibiaoForm.formName == 'htcj'" style="">
                  <!--                 这里要用 dataProviderNameSelect才能选择的人显示人，选择的部门显示部门，不能用dataProvider-->
                  {{ scope.row.dataProviderNameSelect }}
                  <i
                    v-if="
                      zhibiaoForm.contractAuditStatus == 0 ||
                      zhibiaoForm.taskDefKey.indexOf('usertask5') != -1 ||
                      (zhibiaoForm.formName == 'htcj' &&
                        scope.row.auditStatus == 1)
                    "
                    style="margin-left: 5px; color: #1a71fb; cursor: pointer"
                    @click="addUser('ndts', 'ndcj', scope.row, scope.$index)"
                    class="el-icon-edit-outline"
                  ></i>
                </div>
                <!--                指标拟定-->
                <div v-else-if="zhibiaoForm.formName == 'zbnd'">
                  <div v-if="zhibiaoForm.tgLx == 2">
                    {{ scope.row.targetUserName }}
                    <i
                      v-if="scope.row.auditStatus == 1"
                      style="margin-left: 5px; color: #1a71fb; cursor: pointer"
                      @click="addUser('ndts', 'ndcj', scope.row, scope.$index)"
                      class="el-icon-edit-outline"
                    ></i>
                  </div>
                  <div v-else>
                    {{ scope.row.dataProviderNameSelect }}
                    <i
                      v-if="scope.row.auditStatus == 1"
                      style="margin-left: 5px; color: #1a71fb; cursor: pointer"
                      @click="addUser('ndts', 'ndcj', scope.row, scope.$index)"
                      class="el-icon-edit-outline"
                    ></i>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              type="index"
              width="80"
              header-align="center"
              align="center"
              label="排序号"
            ></el-table-column>
            <el-table-column
              prop="auditStatus"
              label="状态"
              min-width="120"
              header-align="center"
              align="center"
              :formatter="auditStatusFormater"
            >
            </el-table-column>
          </el-table>
          <el-table
            :data="dataList"
            border
            style="width: 100%"
            min-height="60vh"
            :row-key="getRowKeys"
            v-if="zhibiaoForm.enter == 2 || zhibiaoForm.enter == 3"
            @load="dataListLoading"
            class="avue-cruds"
            ref="table2"
          >
            <el-table-column
              type="selection"
              v-if="this.htqdorwbsh == 'wbsh'"
              width="55"
              header-align="center"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="zhibiaoType"
              label="指标类别"
              min-width="90"
              header-align="center"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="zhibiaoName"
              label="指标名称"
              min-width="120"
              show-overflow-tooltip
              header-align="center"
              align="left"
            >
            </el-table-column>
            <el-table-column
              prop="weight"
              label="权重(%)"
              min-width="90"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <span v-if="editFlag == 0 || zhibiaoForm.status == 1">{{
                  scope.row.weight
                }}</span>
                <el-input
                  v-else
                  type="number"
                  :min="0.1"
                  :max="100"
                  v-model="scope.row.weight"
                  size="mini"
                  placeholder="请输入内容"
                  @change="saveProperty(scope.row, scope.$index)"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="formulaId"
              label="计算公式"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <div v-if="editFlag == 0 || zhibiaoForm.status == 1">
                  <span v-for="item in formulaOptions">
                    <span v-if="item.id == scope.row.formulaId">
                      {{ item.gsMc }}
                    </span>
                  </span>
                </div>
                <el-select
                  v-else
                  v-model="scope.row.formulaId"
                  placeholder="请选择"
                  :clearable="true"
                  size="mini"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in formulaOptions"
                    :key="item.id"
                    :label="item.gsMc"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="targetValue"
              label="目标值"
              min-width="250"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <div
                  style="white-space: pre-wrap"
                  v-if="editFlag == 0 || zhibiaoForm.status == 1"
                  v-html="scope.row.targetValue"
                ></div>
                <el-input
                  v-else
                  v-model="scope.row.targetValue"
                  size="mini"
                  :rows="1"
                  placeholder="请输入内容"
                  type="textarea"
                  @change="saveProperty(scope.row, scope.$index)"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="unit"
              label="单位"
              min-width="90"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <span v-if="editFlag == 0 || zhibiaoForm.status == 1">{{
                  scope.row.unit
                }}</span>
                <el-input
                  v-else
                  v-model="scope.row.unit"
                  size="mini"
                  placeholder="请输入内容"
                  @change="saveProperty(scope.row, scope.$index)"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="increaseDecrease"
              label="上年度完成值"
              min-width="120"
              header-align="center"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="increaseDecrease"
              label="增减幅度"
              min-width="90"
              header-align="center"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="targetValueType"
              label="完成值获取方式"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <div v-if="editFlag == 0 || zhibiaoForm.status == 1">
                  <span v-for="item in typeList">
                    <span v-if="item.value == scope.row.targetValueType">
                      {{ item.name }}
                    </span>
                  </span>
                </div>
                <el-select
                  v-else
                  v-model="scope.row.targetValueType"
                  size="mini"
                  @change="saveProperty(scope.row, scope.$index)"
                >
                  <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="dataProvider"
              v-if="this.htqdorwbsh == 'htqd' || this.htqdorwbsh == 'wbsh'"
              label="数据提供部门/人"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.tgLx == 2">
                  {{ scope.row.targetUserName }}
                </div>
                <div v-else>
                  {{ scope.row.dataProvider }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="dataProviderId"
              v-else
              label="数据提供部门/人"
              min-width="180"
              header-align="center"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.dataProviderIdSelect"
                  placeholder=""
                  filterable
                  @change="handleProviderChange(scope.row, scope.row.tgLx)"
                >
                  <el-option
                    v-for="(item, index) in scope.row.providerList"
                    :label="item.label"
                    :value="item.val"
                    :key="index"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="auditStatus"
              label="状态"
              min-width="120"
              header-align="center"
              align="center"
              :formatter="auditStatusFormater"
            >
            </el-table-column>
          </el-table>
          <el-dialog
            title="业绩合同指标库"
            :visible.sync="dialogVisible"
            width="80%"
            append-to-body
          >
            <zhibiaoTable
              ref="zhibiaoRef"
              :hetongId="hetongId"
              @func="getRow"
            ></zhibiaoTable>
            <span slot="footer" class="dialog-footer">
              <el-button plain type="primary" @click="addZhibiao"
                >添 加</el-button
              >
              <el-button plain @click="dialogVisible = false">取 消</el-button>
            </span>
          </el-dialog>
          <el-col
            :span="24"
            style="text-align: center; margin-top: 20px"
            v-if="zhibiaoForm.enter == 3"
          >
            <el-button plain type="primary" @click="close('关闭')"
              >返回</el-button
            >
          </el-col>
        </div>
      </div>
      <!--  选择人员信息-->
      <UserCommonSelect
        v-if="usercomment"
        ref="usercomment"
        @submitfy="submitfy"
      ></UserCommonSelect>
      <!--      拟定推送的人员机构信息选择-->
      <FormulateDialog
        v-if="formulateDialog"
        ref="formulateDialog"
        @submitfy="submitfy"
      ></FormulateDialog>
      <!--      指标复用/推送-->
      <HeTongBaseTable
        v-if="showHtTable"
        ref="hetongbasetable"
        :hetongId="hetongId"
        @selectedData="selectedData"
      ></HeTongBaseTable>
    </basic-container>
  </div>
</template>

<script>
import {
  fetchList,
  addObj,
  getObj,
  delObj,
  putObj,
  getListByzbnd,
  getListByzbnd2,
  getFormula,
  saveHtData,
  getDataProvider,
  deleteBatch,
  okAllApi,
  okAllByWbsh,
  backAllApi,
  htzbisflag,
  addHetongHtzb,
  copyZhiBiao,
  checkHqcollections,
  process,
  saveZhibiaoSort,
} from "@/api/hetongrenwu/hetongyeji/hetongzb";
import Sortable from "sortablejs";
import { randomLenNum } from "@/util/util";
import zhibiaoTable from "@/views/hetongrenwu/hetong/hetongyeji/zhibiaoTable";
import { saveZB, saveZBC } from "@/api/hetongrenwu/zhibiaoTable";
import {
  copyZhiBiaoh,
  tsHengTong,
  tsZhibiaoToNiDing,
  tsZhibiaoToHetong,
} from "@/api/hetongrenwu/hetongyeji/hetongnd";
import contractDetailHeader from "./contractDetailHeader";
import UserCommonSelect from "@/views/hetongrenwu/components/usercomment-select";
import FormulateDialog from "@/views/hetongrenwu/hetong/hetongyeji/hetonghtxxdjb/formulateDialog";
import HeTongBaseTable from "@/views/hetongrenwu/components/hetong-base-table";
import { jgtbExportExcel } from "@/api/hetongrenwu/hetongjgtb";
import store from "@/store";
import request from "@/router/axios";
import { getStore } from "@/util/store";
export default {
  components: {
    UserCommonSelect,
    FormulateDialog,
    zhibiaoTable,
    HeTongBaseTable,
    contractDetailHeader,
  },
  name: "zhibiao-form",
  props: {
    zhibiaoForm: {
      disabled: false,
      streamId: "",
      taskId: "",
      id: "",
      titleName: "",
    },
    hetongId: Number,
    hetong: {},
    htqdorwbsh: "",
    contractName: "",
    radio: "",
  },
  data() {
    return {
      kuShow: true,
      editFlag: 1,
      streamId: Number,
      dialogVisible: false,
      formulaOptions: [],
      dataListLoading: false,
      form: {},
      options: [
        { label: "2021年全员绩效考核通用流程", value: "1" },
        { label: "2021年第一季度技术合同流程", value: "2" },
      ],
      leveList: [
        { value: "1", label: "一级合同" },
        { value: "2", label: "二级合同" },
        { value: "3", label: "三级合同" },
        { value: "4", label: "四级合同" },
        { value: "5", label: "五级合同" },
      ],
      modelList: [
        { label: "多人共享成绩", value: "0" },
        { label: "生成多个合同", value: "1" },
      ],
      periodList: [
        { value: "1", label: "月度" },
        { value: "2", label: "季度" },
        { value: "3", label: "年度" },
      ],
      typeList: [
        { name: "手工填报", value: "0" },
        { name: "自动获取", value: "1" },
      ],
      peopleSend: ["张三"],
      promisee: ["李四"],
      zhiList: [
        { value: "模板导出", label: "模板导出" },
        { value: "模板导入", label: "模板导入" },
      ],
      dataList: [],
      searchadvanced: false,
      searchheight: "0",
      isaddflag: "0",
      myhetongid: "",
      usercomment: false,
      shouyuerendataList: [],
      fayuerendataList: [],
      providerList: [
        // {value: "1", label: "数据来源部门",id:0},
      ],
      isShow: "0",
      showHtTable: false,
      shouyueNameList: "",
      loading: false,
      lastPage: "",
      isHideBtn: false,
      newRows: [],
      formulateDialog: false,
      ndtsNdCjRow: {},
      fileList: [],
      providerIndex: null,
      headers: {
        'TENANT-ID': getStore({ name: "tenantId" })
          ? getStore({ name: "tenantId" })
          : "1",
        Authorization: "Bearer " + store.getters.access_token,
      },
    };
  },
  created() {},
  methods: {
    saveOrderBtn() {
      if (this.dataList.length > 1) {
        saveZhibiaoSort({ rows: this.dataList }).then((res) => {
          this.getDataList();
        });
      } else {
        this.$message.warning("无法排序");
      }
    },
    handleUploadSuccess(response, file, fileList) {
      this.showExist = true;
      if (response.code !== 0) {
        this.$message.error("上传出错：" + response.msg);
        return;
      }
      this.bLoading = true;

      request({
        url:
          "/appr-contract/hetonghtzb/allocationFile/" +
          response.data.bucketName +
          "/" +
          response.data.fileName,
        method: "get",
      })
        .then((res) => {
          console.log(JSON.stringify(res.data.data));
          this.getDataList();
          this.bLoading = false;
          this.$message.closeAll();
          this.$message.success("导入成功!");
        })
        .catch((error) => {
          this.bLoading = false;
        });
    },
    beforeFileUpload(file) {
      const cType = file.type;
      let isXls = false;
      if (
        cType === "application/vnd.ms-excel" ||
        cType ===
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      ) {
        isXls = true;
      }

      if (!isXls) {
        this.$message.error("导入文件只能是 Excel 格式!");
      }
      return isXls;
    },
    handleChange(file, fileList) {
      this.fileList = [];
      this.fileList.push(file);
    },

    //增加人员
    addUser(type, lastPage, row, index) {
      if (type == "ndts") {
        this.formulateDialog = true;
        this.jsonData = JSON.stringify([this.hetongId]);
        this.providerIndex = index;
        this.$nextTick(() => {
          this.$refs.formulateDialog.init("12", type, this.jsonData, lastPage);
        });
        this.ndtsNdCjRow = row; //用于合同创建时，更改指标的时候数据提供部门/人选择之后数据存储记录
      } else {
        this.usercomment = true;
        if (type == "fy") {
          this.jsonData = JSON.stringify(this.fayuerendataList);
        } else {
          this.jsonData = JSON.stringify(this.shouyuerendataList);
        }
        this.$nextTick(() => {
          this.$refs.usercomment.init("12", type, this.jsonData);
        });
      }
    },
    //确定选择的人员
    submitfy(data) {
      if (data.type == "ndts") {
        this.dataList[this.providerIndex].tgLx = data.tgLx;
        if (data.tgLx == "1") {
          this.dataList[this.providerIndex].dataProvider =
            data.selectorgdata[0].deptName;
          this.dataList[this.providerIndex].dataProviderId =
            data.selectorgdata[0].deptId;
          this.dataList[this.providerIndex].targetUserName =
            data.selectorgdata[0].ryName;
          this.dataList[this.providerIndex].targetUserId =
            data.selectorgdata[0].userId;
        } else if (data.tgLx == "2") {
          this.dataList[this.providerIndex].targetUserName =
            data.tableDataUser[0].ryName;
          this.dataList[this.providerIndex].targetUserId =
            data.tableDataUser[0].userId;
          this.dataList[this.providerIndex].dataProvider =
            data.tableDataUser[0].deptName;
          this.dataList[this.providerIndex].dataProviderId =
            data.tableDataUser[0].deptId;
        }
        this.resetDataList();
        this.saveProperty(this.dataList[this.providerIndex]); //为了把数据传给合同创建的htzbList
      } else if (data.type == "fy") {
        this.fayuerendataList = data.tableDataUser;
      } else if (data.type == "sy") {
        this.shouyuerendataList = data.tableDataUser;
      }
    },
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "50";
      }
    },
    close(type) {
      this.$emit("zhibiaoChild", type);
    },
    getDataList() {
      this.dataListLoading = true;
      this.myhetongid = this.hetongId;
      //显示所有指标
      if (this.zhibiaoForm.enter == 0 || this.zhibiaoForm.enter == 2) {
        var params = {
          htId: this.hetongId,
          str: 1,
          zhibiaoName: this.form.zhibiaoName,
          zhibiaoType: this.form.zhibiaoType,
          ndId: this.zhibiaoForm.id,
        };
        getListByzbnd(params).then((response) => {
          if (this.zhibiaoForm.enter == 0) {
            this.dataList = this.gettimeStamp(response.data.data);
          } else {
            this.dataList = response.data.data;
          }
          this.resetDataList();
          this.dataListLoading = false;
          this.rowDrop();
        });
        //显示自己部门指标
      } else if (this.zhibiaoForm.enter == 1) {
        var params = {
          htId: this.hetongId,
          ndId: this.zhibiaoForm.id,
          targetUserId: this.zhibiaoForm.ndUserId,
          str: 2,
          zhibiaoName: this.form.zhibiaoName,
          zhibiaoType: this.form.zhibiaoType,
        };
        getListByzbnd2(params).then((response) => {
          this.dataList = response.data.data;
          this.resetDataList();
          this.dataListLoading = false;
        });
      }
      this.getXiaLa();
    },
    // 驳回
    rejectedBtn() {
      var rows = this.$refs.table.selection;
      if (rows.length == 0) {
        this.$message.closeAll();
        this.$message.warning("请勾选指标");
      } else {
        checkHqcollections({ proceId: this.zhibiaoForm.proceid }).then(
          (res) => {
            if (res.data.data) {
              process({
                rows: rows,
                id: this.zhibiaoForm.rowid,
              }).then((res) => {
                this.$message.closeAll();
                this.$message.success("驳回成功");
                this.$emit("zhibiaoChild", "驳回");
              });
            } else {
              this.$message.closeAll();
              this.$message.warning("在汇总过程中没有指标拟定,无法驳回");
            }
          }
        );
      }
    },
    getXiaLa() {
      getFormula().then((res) => {
        this.formulaOptions = res.data.data;
      });
      getDataProvider().then((res) => {
        if (res.data.data) {
          this.providerList = res.data.data;
          this.dataListLoading = false;
        }
      });
    },
    //重组dataList
    resetDataList() {
      this.dataList = this.dataList.map((item) => {
        item.providerList = [];
        item.tgLx = (item.tgLx ? item.tgLx : this.zhibiaoForm.tgLx) || "1";
        //tgLx等于1是机构，2是个人
        if (item.tgLx == "2") {
          item.dataProviderIdSelect = item.targetUserId;
          item.dataProviderNameSelect = item.targetUserName;
        } else {
          item.dataProviderIdSelect = item.dataProviderId;
          item.dataProviderNameSelect = item.dataProvider;
        }
        if (item.targetUserId) {
          item.providerList.push({
            val: item.targetUserId,
            label: item.targetUserName,
          });
        }
        if (item.dataProviderId) {
          item.providerList.push({
            val: item.dataProviderId,
            label: item.dataProvider,
          });
        }
        if (item.targetValue) {
          item.targetValue = item.targetValue.replace(/(；|;)/g, ";\n");
        }
        return item;
      });
    },
    // 修改属性
    editProperty(row, index) {
      if (this.zhibiaoForm.enter == 0 || this.zhibiaoForm.enter == 1) {
        this.isShow = 1;
      } else if (this.zhibiaoForm.enter == 2 || this.zhibiaoForm.enter == 3) {
        this.isaddflag = 1;
      }
    },
    //更改数据提供部门
    handleProviderChange(row, tgLx) {
      row.tgLx = tgLx == "1" ? "2" : "1";
      this.saveProperty(row);
    },
    // 保存属性
    saveProperty(row, index) {
      if (this.zhibiaoForm.enter != 0) {
        row.edit = false;

        putObj(row).then((res) => {
          if (res.data.data) {
            this.$notify.closeAll();
            this.$notify.success("保存成功");
          }
          //刷新列表
          this.getDataList();
        });
      } else {
        this.$emit("zhibiaoChild", this.dataList);
      }
    },
    //批量保存
    saveZBData() {
      this.$notify.closeAll();
      this.$notify.success("保存成功");
    },
    // 取消编辑
    cancelProperty(row, index) {
      if (this.zhibiaoForm.enter == 0 || this.zhibiaoForm.enter == 1) {
        this.isShow = 0;
      } else if (this.zhibiaoForm.enter == 2 || this.zhibiaoForm.enter == 3) {
        this.isaddflag = 0;
      }
      this.$set(this.dataList[index], "isEditPropertyShow", false);
      this.getDataList();
    },
    editRow(row, index) {
      this.$set(this.dataList[index], "edit", true);
    },
    // 删除
    deleteHandle(row) {
      this.$confirm("是否确认删除" + row.zhibiaoName + "指标", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(row.id);
        })
        .then((data) => {
          this.$message.closeAll();
          this.$message.success("删除成功");
          this.getDataList();
        });
    },
    showZhibiaoTable() {
      this.dialogVisible = true;
      if (this.zhibiaoForm.enter == 0) {
        this.$nextTick(() => {
          this.$refs.zhibiaoRef.hetongEnter(
            this.zhibiaoForm.enter,
            this.zhibiaoForm.formName
          );
        });
      } else {
        this.$nextTick(() => {
          this.$refs.zhibiaoRef.getDataList(this.zhibiaoForm.formName);
        });
      }
    },
    addZhibiao() {
      if (this.zhibiaoForm.enter == 0) {
        addHetongHtzb({
          rows: this.newRows,
          hetongId: this.hetongId,
          ndId: this.form.id,
        }).then((res) => {
          if (this.dataList.concat(res.data.data).length == 1) {
            this.dataList = this.dataList.concat(
              this.gettimeStamp(res.data.data)
            );
            this.dialogVisible = false;
            this.resetDataList();
            this.getXiaLa();
            this.$emit("zhibiaoChild", this.dataList);
          } else {
            this.uniqueTwo(
              this.dataList.concat(this.gettimeStamp(res.data.data)),
              "新增"
            );
          }
        });
      } else {
        this.$refs.zhibiaoRef.saveZhibiao(this.dataList);
      }
    },
    //生成时间戳
    gettimeStamp(data) {
      data.forEach((item, index) => {
        let t = new Date().getTime() + index;
        item.timeStamp = randomLenNum(5, index);
        return item;
      });

      return data;
    },
    getRow(rows) {
      rows = rows.map((item) => {
        item.tgLx = item.tgLx ? item.tgLx : this.zhibiaoForm.tgLx;
        return item;
      });
      if (this.zhibiaoForm.enter == 0) {
        this.newRows = rows;
      } else {
        saveZB({
          rows: rows,
          hetongId: this.hetongId,
          ndId: this.hetong.id,
        }).then((res) => {
          this.dialogVisible = false;
          this.getDataList();
          this.$forceUpdate();
        });
      }
    },
    // 对比重复
    uniqueTwo(arr, text) {
      var tianText = "";
      for (var i = 0; i < arr.length; i++) {
        for (var j = i + 1; j < arr.length; j++) {
          if (arr[i].zhibiaoName == arr[j].zhibiaoName) {
            tianText = tianText + arr[i].zhibiaoName + ",";
          } else {
            this.dataList = arr;
            this.resetDataList();
          }
        }
      }
      if (tianText != "") {
        this.$confirm("指标名称" + tianText + "相同，是否继续" + text, "提示", {
          confirmButtonText: "",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.dataList = arr;
            this.resetDataList();
            this.dialogVisible = false;
            this.$emit("zhibiaoChild", this.dataList);
          })
          .catch(() => {
            this.dataList = this.uniqueTree(arr);
            this.resetDataList();
          });
      } else {
        this.dataList = arr;
        this.resetDataList();
        this.dialogVisible = false;
        this.$emit("zhibiaoChild", this.dataList);
      }
      this.getXiaLa();
    },
    uniqueTree(arr) {
      for (var i = 0; i < arr.length; i++) {
        for (var j = i + 1; j < arr.length; j++) {
          if (arr[i].zhibiaoName == arr[j].zhibiaoName) {
            arr.splice(j, 1);
            j--;
          }
        }
      }
      return arr;
    },
    saveData() {
      this.form.fayuejson = JSON.stringify(this.fayuerendataList);
      this.form.shouyuejson = JSON.stringify(this.shouyuerendataList);
      saveHtData(this.form).then((res) => {
        this.$message.closeAll();
        this.$message.success("保存成功");
      });
    },
    saveForm(htForm) {
      this.fayuerendataList = JSON.parse(htForm.fayuejson);
      if (htForm.type == 2) {
        if (htForm.multiMode == 0) {
          this.shouyueNameList = htForm.jigouName;
        } else {
          this.shouyuerendataList = JSON.parse(htForm.jigoujson);
        }
      } else {
        if (htForm.multiMode == 1) {
          this.shouyueNameList = htForm.shouyueName;
        } else {
          this.shouyuerendataList = JSON.parse(htForm.shouyuejson);
        }
      }
      this.lastPage = htForm.lastPage;
      this.isHideBtn = htForm.isHideBtn;
      this.form = htForm;
      this.getDataList();
    },
    setenter() {
      this.showZhibiaoTable();
    },
    okAll() {
      var data = this.$refs.table2.selection;
      if (data.length == 0) {
        data = this.$refs.table2.data;
      }
      var taskId = this.zhibiaoForm.taskId;
      if (this.htqdorwbsh == "wbsh") {
        this.$confirm("是否要通过指标？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            const params = {
              rows: data,
              taskId: taskId,
            };
            okAllByWbsh(params)
              .then((res) => {
                this.$message.closeAll();
                this.$message.success('审批通过');
                this.loading = false;
                this.close("关闭");
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
                this.getDataList();
                this.close("关闭");
              });
          })
          .catch(() => {
            this.$message.closeAll();
            this.$message({
              type: "info",
              message: "已取消提交",
            });
            this.close("关闭");
          });
      } else {
        this.$confirm("是否要通过指标？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.loading = true;
            const params = {
              rows: data,
              taskId: taskId,
            };
            okAllApi(params)
              .then((res) => {
                this.$message.closeAll();
                this.$message.success('审批通过');
                this.loading = false;
                this.close("关闭");
              })
              .catch(() => {
                this.$message.closeAll();
                this.$message({
                  type: "error",
                  message: "提交失败!",
                });
                this.close("关闭");
                this.getDataList();
              });
          })
          .catch(() => {
            this.$message.closeAll();
            this.$message({
              type: "info",
              message: "已取消提交",
            });
            this.close("关闭");
          });
      }
    },
    //批量驳回
    backAll() {
      var rows = this.$refs.table2.selection;
      if (rows.length == 0) {
        rows = this.$refs.table2.data;
      }
      var taskId = this.zhibiaoForm.taskId;
      this.$confirm("是否要驳回指标?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var params = {
            rows: rows,
            taskId: taskId,
            formName: this.zhibiaoForm.formName,
          };
          backAllApi(params)
            .then((res) => {
              this.$message.closeAll();
              this.$message({
                type: "info",
                message: res.data.data + "条指标已处理",
              });
              this.close("关闭");
            })
            .catch(() => {
              this.$message.closeAll();
              this.$message({
                type: "error",
                message: "提交失败!",
              });
            });
        })
        .catch(() => {
          this.$message.closeAll();
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    //拆分字段
    cutout(cellValue) {
      if (cellValue) {
        var c = cellValue.split(",");
        if (c.size < 1) {
          c.push("-");
          c.push("-");
        } else if (c.size < 2) {
          c.push("-");
        }
        return c;
      }
    },
    deleteBatch() {
      var data = [];
      if (this.zhibiaoForm.enter == 0 || this.zhibiaoForm.enter == 1) {
        data = this.$refs.table.selection;
      } else if (this.zhibiaoForm.enter == 2 || this.zhibiaoForm.enter == 3) {
        data = this.$refs.table2.selection;
      }
      if (data.length == 0) {
        this.$message.closeAll();
        this.$message.error("请至少选择一个指标！");
        return;
      }
      if (this.zhibiaoForm.enter == 0) {
        this.$confirm("是否要删除吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            if (this.zhibiaoForm.titleName == "编辑") {
              var ids = [];
              for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
              }
              var idsStr = ids.join(",");
              deleteBatch({ ids: idsStr }).then((res) => {
                this.$message.closeAll();
                this.$message.success("删除成功");
                this.getDataList();
              });
            } else {
              var list = [];
              data.forEach((item) => {
                var findIndex = this.dataList.findIndex(
                  (obj) =>
                    obj.timeStamp == item.timeStamp &&
                    obj.zhibiaoName == item.zhibiaoName
                );
                item.dataState = 1;
                list.push(item);
                this.dataList.splice(findIndex, 1);
              });
              this.resetDataList();
              list = list.concat(this.dataList);
              this.$emit("zhibiaoChild", list);
            }
          })
          .catch(() => {});
      } else {
        var ids = [];
        for (var i = 0; i < data.length; i++) {
          ids.push(data[i].id);
        }
        var idsStr = ids.join(",");
        this.$confirm("是否要删除吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return deleteBatch({ ids: idsStr });
          })
          .then((data) => {
            this.$message.closeAll();
            this.$message.success("删除成功");
            this.getDataList();
          });
      }
    },
    copyZhibiao(type) {
      var select = [];
      if (this.$refs.table.selection.length == 0) {
        select = this.dataList;
      } else {
        select = this.$refs.table.selection;
      }
      for (var i = 0; i < select.length; i++) {
        if (select[i].id == null) {
          this.$message.closeAll();
          this.$message.warning("请先保存当前指标");
          return false;
        }
      }
      this.showHtTable = true;
      this.$nextTick(() => {
        this.$refs.hetongbasetable.initData(
          type,
          this.zhibiaoForm.formName,
          this.zhibiaoForm.id,
          select
        );
      });
    },
    //操作复用指标/推送
    selectedData(childData) {
      this.showHtTable = false;
      this.hetongId = this.hetongId;
      var _this = this;
      if (childData.operType == "fy") {
        if (this.zhibiaoForm.enter == 0) {
          copyZhiBiao({ id: childData.rows[0].id }).then((res) => {
            if (res.data.data.length > 0) {
              res.data.data.forEach((item) => {
                item.auditStatus = "1";
              });
            }
            if (this.dataList.concat(res.data.data).length == 1) {
              this.dataList = this.dataList.concat(
                this.gettimeStamp(res.data.data)
              );
              this.resetDataList();
              this.getXiaLa();
              this.$emit("zhibiaoChild", this.dataList);
            } else {
              this.uniqueTwo(
                this.dataList.concat(this.gettimeStamp(res.data.data)),
                "复用"
              );
            }
          });
        } else {
          var ids = [];
          ids.push(childData.rows[0].id);
          var params = {
            htzblist: this.dataList,
            htid: ids,
            enter: this.zhibiaoForm.enter,
            ndId: this.hetong.id,
          };
          htzbisflag(params).then((res) => {
            if (res.data.data) {
              this.$confirm(
                "指标名称" + res.data.data + "相同，是否继续复用指标",
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                }
              )
                .then(function () {
                  var params = {
                    id: childData.rows[0].id,
                    htId: this.hetongId,
                    ndId: this.hetong.id,
                  };
                  return copyZhiBiaoh(params);
                })
                .then((data) => {
                  _this.getDataList();
                  this.$message.closeAll();
                  this.$message.success("复用指标成功");
                });
            } else {
              this.$confirm("是否要复用该合同指标吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(function () {
                  var params = {
                    id: childData.rows[0].id,
                    htId: _this.hetongId,
                    ndId: _this.hetong.id,
                  };
                  return copyZhiBiaoh(params);
                })
                .then((data) => {
                  _this.getDataList();
                  this.$message.closeAll();
                  this.$message.success("复用指标成功");
                });
            }
          });
        }
      } else if (childData.operType == "ts") {

        
        var ids2 = [];
        for (var i = 0; i < childData.rows.length; i++) {
          if(childData.rows[i].htId){
            ids2.push(childData.rows[i].htId + ";" + childData.rows[i].id);
          }else{
            ids2.push(childData.rows[i].id + ";0");
          }
        }

        var ids = "";
        var zhibiaoIds = [];
        childData.rows.forEach((ele) => {
          ids = ids + ele.id + ",";
        });
        childData.previousList.forEach((ele) => {
          // zhibiaoIds = zhibiaoIds + ele.id + ",";
          zhibiaoIds.push(ele.id);
        });
        var params = {
          htzblist: this.dataList,
          htid: ids2,
          enter: this.zhibiaoForm.enter,
        };
        htzbisflag(params).then((res) => {
          if (res.data.data) {
            this.$confirm(
              "指标名称" + res.data.data + "相同，是否继续推送到其他合同",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              }
            )
              .then(function () {
                var params = {
                  ids: ids2,
                  zhibiaoIds: zhibiaoIds,
                };
                if (childData.type != null) {
                  if (childData.type == "yjht") {
                    return tsZhibiaoToHetong(params);
                  }
                } else {
                  return tsZhibiaoToNiDing(params);
                }
              })
              .then((data) => {
                _this.getDataList();
                this.$message.closeAll();
                this.$message.success("已推送到其他合同");
              });
          } else {
            this.$confirm("是否要推送到其他合同吗？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(function () {
                var params = {
                  ids: ids2,
                  zhibiaoIds: zhibiaoIds,
                };
                if (childData.type != null) {
                  if (childData.type == "yjht") {
                    return tsZhibiaoToHetong(params);
                  }
                } else {
                  return tsZhibiaoToNiDing(params);
                }
              })
              .then((data) => {
                _this.getDataList();
                this.$message.closeAll();
                this.$message.success("已推送到其他合同");
              });
          }
        });
      }
    },
    exportExcel() {
      var ids = [];
      ids.push(this.hetongId);
      var filename = "";
      if (ids.length > 1) {
        filename = this.contractName + " 指标明细表.zip";
      } else {
        filename = this.contractName + " 指标明细表" + ".xlsx";
      }
      console.log(this.zhibiaoForm.id + " this.zhibiaoForm.id");
      jgtbExportExcel({
        ids: ids,
        type: "zbfm",
        ndid: this.zhibiaoForm.id,
      }).then((response) => {
        this.$message.closeAll();
        this.$message.success("导出成功!");
        let url = window.URL.createObjectURL(new Blob([response.data]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", filename);
        document.body.appendChild(link);
        link.click();
      });
    },
    /*checkboxSelect (row, rowIndex) {
      if ((this.htqdorwbsh == 'wbsh') && row.auditStatus>="1") {
        return false
      }else{
        return true
      }
    },*/
    selectable(row, index) {
      if (this.zhibiaoForm.status == 1) {
        return false;
      } else {
        return true;
      }
    },
    auditStatusFormater(row, column) {
      const auditStatus = row.auditStatus;
      if (auditStatus == 0) {
        return "未提报";
      } else if (auditStatus == 1) {
        return "填报中";
      } else if (auditStatus == 2) {
        return "审核中";
      } else if (auditStatus == 3) {
        return "已经审核";
      } else if (auditStatus == 4) {
        return "审核驳回";
      } else if (auditStatus == 5) {
        return "结果填报中";
      } else if (auditStatus == 6) {
        return "结果填报完成";
      } else if (auditStatus == 7) {
        return "填报审核驳回";
      }
    },
    editLock() {
      this.editFlag = 0;
    },
    getRowKeys(row) {
      return row.id;
    },
    // 行拖拽
    rowDrop() {
      const tbody = document.querySelector(
        ".avue-cruds .el-table__body-wrapper tbody"
      );
      const _this = this;
      Sortable.create(tbody, {
        onEnd({ newIndex, oldIndex }) {
          const currRow = _this.dataList.splice(oldIndex, 1)[0];
          _this.dataList.splice(newIndex, 0, currRow);
          _this.$nextTick((res) => {
            _this.$forceUpdate();
            //  _this.saveOrderBtn()
          });
        },
      });
    },
  },
};
</script>

<style>
.zhibiaoHead {
  border: 1px solid grey;
  text-align: center;
  line-height: 30px;
}
</style>
